package com.zw.healthy.controller;


import com.zw.commons.log.annotation.Log;
import com.zw.commons.log.enums.BusinessType;
import com.zw.commons.utlis.JwtHelper;
import com.zw.healthy.service.HealthClockService;
import com.zw.object.healthy.HealthClock;
import com.zw.object.result.Result;
import com.zw.object.vo.ClockInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.Clock;

/**
 * <p>
 * 打卡健康表 前端控制器
 * </p>
 *
 * @author zw
 * @since 2023-03-12
 */
@RestController
@RequestMapping("/healthy/health-clock")
@Api(tags = "健康打卡")
public class HealthClockController {
    @Autowired
    private HealthClockService healthClockService;

    @ApiOperation("健康打卡")
    @PostMapping("/clock")
    @Log(title = "健康打卡",businessType = BusinessType.INSERT)
    public Result clock(@Validated @RequestBody HealthClock healthClock, HttpServletRequest request){
        healthClock.setId(JwtHelper.getUserId(request.getHeader("token")));
        healthClock.setUsername(JwtHelper.getUsername(request.getHeader("token")));
        healthClock.setDeptId(1);
        return healthClockService.saveClock(healthClock);
    }

    @PostMapping("/list")
    @ApiOperation("打卡信息")
    @Log(title = "打卡信息",businessType = BusinessType.SELECT)
    public Result clockList(@Validated @RequestBody ClockInfoVo vo,HttpServletRequest request){
        String token = request.getHeader("token ");
        return healthClockService.clockInfoList(vo,token);
    }
}

